<?php
/**
 * 主导航菜单widget
 */
class main_menuWidget extends Widget {

	public function render(){
        //获取当前action名称及页面ID
        $action_id = doit::get_action_id();
        if($action_id == 'page') {
            $post_id = (int)$this->get('id');
        }
        
        //instance model
        $post_model = $this->model('posts');
        
        $post_data = $post_model->getAll('post_type=1', null, array('post_id', 'post_title'), 'post_id asc');
        
        echo '<table border="0" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC"><tr>';
        
        //菜单：主页
        if ($action_id == 'index') {
            echo '<td width="100" height="40" align="center" class="current_menu">首页</td>';
        } else {
            echo '<td width="100" height="40" align="center"><a href="' .$this->create_url('index/index'). '">首页</a></td>';
        }
        
        //菜单:页面(page)
        if($post_data) {
            foreach ($post_data as $lines) {
                if ($action_id == 'page' && $post_id == $lines['post_id']) {
                    echo '<td width="100" height="40" align="center" class="current_menu">', $lines['post_title'], '</td>';
                } else {
                    echo '<td width="100" align="center"><a href="' . $this->create_url('index/page'). '/?id=' . $lines['post_id'] . '">' . $lines['post_title'] . '</a></td>';
                }
            }
        }
        
        echo '</tr></table>';
	}
}